import Resolver from '../parser/Resolver'
import Parser from '../parser/Parser'
export default class Ele {
    constructor (subject, ele, lazy=false) {
        this.ele = ele
        this.subject = subject
        this.childs = new Set()
        this.parent = null
    }
    getView (){
        return ''
    }
    getResolver () {
        return new Resolver(this.subject, this)
    }
    getParser () {
        return new Parser(this.getView())
    }
    getViewParser () {
        let resolver = this.getResolver()
        if (!(resolver instanceof Resolver)) {
            console.error(this.ele.outerHTML + '：Resolver类型错误')
            resolver = new Resolver(this.subject, this)
        }
        let parser = this.getParser()
        parser.setResolver(resolver)
        return parser.parse()
    }
    append (ele) {
        if(ele instanceof Ele) {
            this.childs.add(ele)
            ele.parent = this
        }else {
            console.error('ele类型非Ele实例')
        }
    }
    draw () {
        this.fn = this.getViewParser()
        this.childs.forEach(function(child, key, own) {
            child.draw()
        })
    }
    update (){
        return
    }
}